﻿(function (win, undefined) {
    F5Frame.register("F5Frame", function (cg) {
        this.Text = function () {
            //继承:对象冒充
            this.newMethod = F5Frame.ObjBase; //把_objbase方法赋给newMethod，
            this.newMethod(); //调用newMethod
            delete this.newMethod; //删除newMethod

            this._width = 0;
            this._height = 0;
            this._text = "";
            this._font = "宋体"; //默认字体
            this._fsize = "10pt";
            this._color = "#000000";

            //创建一段文字
            this.Create = function (options) {
                this._x = options.x || 0;
                this._y = options.y || 0;

                this.setFont(options.font || "微软雅黑");
                this.setFSize(options.fsize || "10pt");
                this.setText(options.text || "");
                this.setAlign(options.align || "left");
                this.setColor(options.color || "#000000");
                this.setzOrder(options.zorder || this.zOrder);
                this.setLayer(options.layer || this.zLayer);

                F5Frame.context2D.font = this.getFont(); ;
                var metrics = F5Frame.context2D.measureText(this._text);
                this._width = metrics.width;

                this._height = 10; // +10 * 0.4;
                F5Frame.addGameObject(this);

                return this;
            }

            //设置文本色
            this.setColor = function (v) {
                this._color = v;
            }
            //设置显示文本
            this.setText = function (v) {
                this._text = v;
            }
            //设置字体
            this.setFont = function (v) {
                this._font = v;
            }
            this.setFSize = function (v) {
                this._fsize = v;
            }

            this.getFont = function () {
                return this._fsize + " " + this._font;
            }

            //返回Y轴
            this.getY = function () {
                ry = 0;
                if (this._align.indexOf("top") > 0) {
                    ry = this._y - this.getHeight() + this.keypoint[0];
                }
                else {
                    ry = this._y + this.getHeight() / 2 + this.keypoint[1];
                }
                return ry;
            }

            //绘制
            this.draw = function (/**Number*/dt, /**CanvasRenderingContext2D*/context) {
                if (this._show) {
                    context.font = this.getFont();
                    context.fillStyle = this._color;
                    context.fillText(this._text, this.getX(), this.getY());
                    this.draw_pick(context);
                }
            }

            this.getWidth = function () {
                //字符串长度*字符像素
                return Number(this._width);
            }
            this.getHeight = function () {
                //字符像素
                return Number(this._height);
            }

            //对象选中
            this.draw_pick = function (context) {
                //啥也不做
                if (this._pick) { }
            }

            //选中判定
            this.jugePick = function (px, py) {
                if (this.isShow()) {
                    //判断鼠标是否在其范围内
                    x1 = this.getX();
                    x2 = this.getX() + this.getWidth();
                    y1 = this.getY() - this._height;
                    y2 = this.getY();
                    if (px >= x1 && px <= x2 && py >= y1 && py <= y2) {
                        return true
                    }
                }
                return false;
            }
        }
    });

})(window, undefined);